﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using KVB.Common;

namespace Customer_Profile.Admin
{
    public partial class CodeModify : System.Web.UI.Page
    {
        private DataSet ds = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["id"] != null)
            {
                if (!Page.IsPostBack)
                {
                    string id = Request.QueryString["id"].ToString();
                    try
                    {
                        CodeDao codedao = new CodeDao();
                        ds = codedao.GetModel(id);
                    }
                    catch (Exception ex)
                    {
                        Log.WriteDefaultLog("modifyCodePage_Load", ex.ToString());
                    }
                    if (ds != null && ds.Tables.Count > 0)
                    {
                        lbType.Text = ds.Tables[0].Rows[0]["codetypename"].ToString();
                        txtName.Value = ds.Tables[0].Rows[0]["CodeName"].ToString();
                        txtValue.Value = ds.Tables[0].Rows[0]["CodeValue"].ToString();
                        txtRemark.Value = ds.Tables[0].Rows[0]["Remark"].ToString();
                        txtOrderid.Value = ds.Tables[0].Rows[0]["CodeOrder"].ToString();
                        drpUsed.Items.FindByValue(ds.Tables[0].Rows[0]["Y_N"].ToString()).Selected = true;
                    }
                }
            }
            else
            {
                Comm.ViewMsgGoUrl("CodeManage.aspx", "Code Not Exist");
            }
        }

        protected void ibtnAdd_ServerClick(object sender, EventArgs e)
        {
            string id = "";
            CodeDao codedao = new CodeDao();
            if (Request.QueryString["id"] != null)
            {
                id = Request.QueryString["id"].ToString();
            }
            try
            {
                codedao.Modify(id, txtName.Value.Trim(), txtValue.Value.Trim(), txtRemark.Value.Trim(), txtOrderid.Value.Trim(), drpUsed.SelectedValue.ToString());
                Comm.ViewAlertMsg("Success");
            }
            catch (Exception ex)
            {
                Log.WriteDefaultLog("CodeModifyibtnAdd_ServerClick", ex.ToString());
            }
        }

        protected void ibtnBack_ServerClick(object sender, EventArgs e)
        {
            try
            {
                Response.Redirect("CodeManage.aspx", false);
            }
            catch (Exception ex)
            {
                Response.Write(ex.ToString());
                Response.End();
            }
        }
    }
}
